﻿namespace UnityEditor.Graphs.AnimationStateMachine
{
    using System;
    using UnityEditor;
    using UnityEditor.Graphs;
    using UnityEditorInternal;
    using UnityEngine;

    [CustomEditor(typeof(StateMachine)), CanEditMultipleObjects]
    internal class StateMachineInspector : Editor
    {
        private SerializedProperty m_Name;
        private StateMachine m_RootStateMachine;

        public void OnEnable()
        {
            this.m_Name = base.serializedObject.FindProperty("m_Name");
            this.m_RootStateMachine = AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine;
        }

        internal override void OnHeaderTitleGUI(Rect titleRect, string header)
        {
            base.serializedObject.Update();
            Rect position = titleRect;
            position.height = 16f;
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_Name.hasMultipleDifferentValues;
            string str = EditorGUI.DelayedTextField(position, this.m_Name.stringValue, null, EditorStyles.textField);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(str))
            {
                foreach (UnityEngine.Object obj2 in base.targets)
                {
                    string name = this.m_RootStateMachine.MakeUniqueStateMachineName(str);
                    ObjectNames.SetNameSmart(obj2, name);
                }
            }
            base.serializedObject.ApplyModifiedProperties();
        }
    }
}

